package com.lhy.service;


import com.lhy.pojo.Gas;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.CriteriaDefinition;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GasService {
    @Resource
    private MongoTemplate mongoTemplate;

    //查询所有
    public Map<String,Object> selectGasList(){
        List<Gas> list = mongoTemplate.findAll(Gas.class,"gas");
        Map<String,Object> gasResult =new HashMap<>();
        if(list==null || list.isEmpty()){
            gasResult.put("code","400");
            gasResult.put("message","没有相关信息");
        }else{
            gasResult.put("code","0");
            gasResult.put("count",list.size());
            gasResult.put("data",list);
            Query query = new Query(Criteria.where("concentration").gte(5));
            Gas danger=mongoTemplate.findOne(query,Gas.class,"gas");
            if(danger!=null) gasResult.put("danger",1);
        }
        return gasResult;
    }
}
